import request from "@/utils/request";

// 用户模块URL
const MENU_BASE_URL = "/admin";

const UserAPI = {
    /**
     * 获取用户列表
     * @param queryParams
     * @returns
     */
    getList(queryParams: any) {
        return request<any, any>({
            url: `${MENU_BASE_URL}/user/list`,
            method: "get",
            params: queryParams,
        });
    },
    /**
     * 获取用户类型下拉列表
     * @param
     * @returns
     */
    getUserType() {
        return request<any, IgetUserType[]>({
            url: `${MENU_BASE_URL}/userType/selectList`,
            method: "get",
        });
    },

    /**
     * 导入用户
     *
     * @param
     * @param
     */
    import(file: File) {
        const formData = new FormData();
        formData.append("file", file);
        return request({
            url: `${MENU_BASE_URL}/user/import`,
            method: "post",
            data: formData,
            headers: {
                "Content-Type": "multipart/form-data",
            },
        });
    },

    /**
     * 表格点击详情
     * @param
     * @returns
     */
    viewUser(id: IviewUserParams) {
        return request<any, IgetUserType[]>({
            url: `${MENU_BASE_URL}/user/detail`,
            method: "get",
            params: id,
        });
    },
    /**
     * 修改表格行状态
     * @param
     * @returns
     */
    updateStatus(params: IupdateStatus) {
        return request<any, IgetUserType[]>({
            url: `${MENU_BASE_URL}/user/updateStatus`,
            method: "post",
            params: params,
        });
    },
    /**
     * 修改用户密码
     * @param
     * @returns
     */
    resetPassword(params: IviewUserParams) {
        return request<any, any>({
            url: `${MENU_BASE_URL}/user/resetPassword`,
            method: "post",
            params: params,
        });
    },

    /**
     * 获取单位列表
     * @param
     * @returns
     */
    getCompany() {
        return request<any, IgetUserType[]>({
            url: `${MENU_BASE_URL}/company/selectList`,
            method: "get",
        });
    },
    /**
     * 获取角色列表
     * @param
     * @returns
     */
    getRoleList() {
        return request<any, any>({
            url: `${MENU_BASE_URL}/userType/selectList`,
            method: "get",
        });
    },
    /**
     * 获取app列表
     * @param
     * @returns
     */
    getAppList() {
        return request<any, any>({
            url: `${MENU_BASE_URL}/menu/getFrontMenuList`,
            method: "get",
        });
    },

    /**
     * 添加用户
     * @param
     * @returns
     */
    addUser(params: any) {
        return request<any, any>({
            url: `${MENU_BASE_URL}/user/add`,
            method: "post",
            params: params,
        });
    },
    /**
     * 获取用户详情
     * @param
     * @returns
     */
    getUserInfo(id: any) {
        return request<any, any>({
            url: `${MENU_BASE_URL}/user/info`,
            method: "get",
            params: { id },
        });
    },
    /**
     * 编辑用户详情
     * @param
     * @returns
     */
    editUserInfo(params: any) {
        return request<any, any>({
            url: `${MENU_BASE_URL}/user/edit`,
            method: "post",
            params: params,
        });
    },
};

export default UserAPI;

interface IgetUserType {
    id: string; //角色id
    type_name: string; //角色名称
}
interface IviewUserParams {
    id: string; //角色id
}
interface IupdateStatus {
    id: string; //角色id
    status: string; //状态
}
interface IgetUserList {}
